package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.Tag;
import com.ruoyi.system.mapper.TagDao;
import com.ruoyi.system.service.TagService;
import org.springframework.stereotype.Service;

/**
 * Auto created by codeAppend plugin
 */
@Service
public class TagServiceImpl extends ServiceImpl<TagDao, Tag> implements TagService {
    @Override
    public boolean addTag(Tag tag) {
        Tag t = new Tag();
        t.setTagName(tag.getTagName());
        return baseMapper.insert(t) > 0;
    }

    @Override
    public boolean deleteTag(Long tagId) {
        return baseMapper.deleteById(tagId) > 0;
    }

    @Override
    public boolean updateTag(Tag tag) {
        LambdaQueryWrapper<Tag> lqw = new LambdaQueryWrapper();
        lqw.eq(Tag::getId, tag.getId());
        Tag t = baseMapper.selectOne(lqw);
        if (t == null){
            throw new RuntimeException("tag not found");
        }
        t.setTagName(tag.getTagName());
        return baseMapper.updateById(t) > 0;
    }

    @Override
    public Tag getTagById(Long tagId) {
        return baseMapper.selectById(tagId);
    }

    // use "baseMapper" to call jdbc
    // example: baseMapper.insert(entity);
    // example: baseMapper.selectByPage(params);

}
